#include "EpilOutputHelper.h"
#include <stdexcept>

using namespace std;


tstring EpilOutputHelper::GetIndent( int indent )
{
	tstring ret = t("");
	for( int i = 0; i < indent; i++ )
	{
		ret += t("    ");
	}
	return ret;
}


tstring EpilOutputHelper::GetUnaryOperator( EpilUnaryOperator op )
{
	switch( op )
	{
	case EUO_Not:
		return t("not");
	case EUO_Opposite:
		return t("-");
	case EUO_Length:
		return t("#");
	default:
		throw runtime_error( "Invalid unary operator detected." );
	}
}


tstring EpilOutputHelper::GetBinaryOperator( EpilBinaryOperator op )
{
	switch( op )
	{
	case EBO_Or:
		return t("or");
	case EBO_And:
		return t("and");
	case EBO_LessThan:
		return t("<");
	case EBO_LessThanOrEqual:
		return t("<=");
	case EBO_GreaterThan:
		return t(">");
	case EBO_GreaterThanOrEqual:
		return t(">=");
	case EBO_Unequal:
		return t("~=");
	case EBO_Equal:
		return t("==");
	case EBO_StringConcatenate:
		return t("..");
	case EBO_Add:
		return t("+");
	case EBO_Minus:
		return t("-");
	case EBO_Multiply:
		return t("*");
	case EBO_Divide:
		return t("/");
	case EBO_Mod:
		return t("%");
	case EBO_Power:
		return t("^");
	default:
		throw runtime_error( "Invalid binary operator detected." );
	}
}


int EpilOutputHelper::GetBinaryOperatorPrecedence( EpilBinaryOperator op )
{
	switch( op )
	{
	case EBO_Or:
		return 1;
	case EBO_And:
		return 2;
	case EBO_LessThan:
	case EBO_LessThanOrEqual:
	case EBO_GreaterThan:
	case EBO_GreaterThanOrEqual:
	case EBO_Unequal:
	case EBO_Equal:
		return 3;
	case EBO_StringConcatenate:
		return 4;
	case EBO_Add:
	case EBO_Minus:
		return 5;
	case EBO_Multiply:
	case EBO_Divide:
	case EBO_Mod:
		return 6;
	case EBO_Power:
		return 8;
	default:
		throw runtime_error( "Invalid binary operator detected." );
	}
}


int EpilOutputHelper::GetUnaryOperatorPrecedence( EpilUnaryOperator op )
{
	switch( op )
	{
	case EUO_Not:
	case EUO_Length:
	case EUO_Opposite:
		return 7;
	default:
		throw runtime_error( "Invalid unary operator detected." );
	}
}